package com.czd.support.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.czd.base.model.Paginate;
import com.czd.base.utils.WebUtils;
import com.czd.support.common.Configuration;
import com.czd.support.model.Investor;
import com.czd.support.service.InvestorService;

/**
 * 
 * @Description  投资人控制类
 * @Author caoren
 * @Date    2015年5月31日 下午2:38:55
 * @Version v1.0
 */
@Controller
@RequestMapping("/investor")
public class InvestorController extends BaseController{
	@Autowired
	private InvestorService investorService;

	/**
	 * 投资人列表
	 * @param investor
	 * @param request
	 * @param model
	 * @param pageNo
	 * @return
	 */
	@RequestMapping(value="/list")
	public String list(Investor investor, HttpServletRequest request, Model model, @RequestParam(value = "pageNo", defaultValue = "1") int pageNo){
		investor.setPageSize(Configuration.getInstance().getDefault_page_size());
		investor.setPageNo(pageNo);
		String kw=WebUtils.findParamStr(request, "kw");
		Paginate paginate=investorService.queryForPage(investor, kw);
		model.addAttribute("paginate",paginate);
		return "/investor/list";
	}
	
	/**
	 * 投资人明细信息
	 * @param userId
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/details/{userId}")
	public String details(@PathVariable int userId, Model model){
		Investor investor = investorService.findById(userId);
		if(investor != null){
			model.addAttribute("investor",investor);
			return "/investor/details";
		}
		return error(model, "投资人信息不存在", "投资人信息不存在");
	}
}
